<template>
	<view class="order-detail">
		<view v-if="info.status == 'normal'" class="status wait">处方待审核中...</view>
		<view v-if="info.status == 'yes'" class="status ok">处方审核已通过</view>
		<view v-if="info.status == 'reject'" class="status fail">处方审核已驳回，原因：{{info.reject_content}}</view>
		<!-- 主体 -->
		<view class="page" :class="{'page-bottom-bar': info.status != 'normal'}">
			<view class="font15 font-b tc">电子处方</view>
			<view class="look" @click="goNext('/pagesA/prescript/note?id=' + info.id + '&mode=doctor')">查看原始处方</view>
			<!-- 患者信息 -->
			<view class="title flex-row-start">
				<view class="name">患者信息</view>
			</view>
			<view class="part1 font12 flex-row-start">
				<view class="photo bg-cover" :style="{backgroundImage: 'url(' + photo + ')'}"></view>
				<text>{{info.user_the_patient_info?info.user_the_patient_info.name:''}}</text>
				<text>{{info.user_the_patient_info?info.user_the_patient_info.mobile:''}}</text>
			</view>
			<!-- 患者信息 -->
			<view class="title flex-row-start">
				<view class="name">诊断医生</view>
			</view>
			<view class="part1 font12 flex-row-start" v-if="info.doctor_info">
				<view class="photo bg-cover" :style="{backgroundImage: 'url(' + info.doctor_info.img + ')'}"></view>
				<text>{{info.doctor_info.name}}</text>
				<text>{{info.doctor_info.mobile}}</text>
			</view>
			<!-- 诊断信息 -->
			<view class="title flex-row-start">
				<view class="name">诊断结果</view>
			</view>
			<view class="part2 font12">{{info.diagnose ? info.diagnose : '暂无'}}</view>
			<!-- 药品信息 -->
			<view class="title flex-row-start">
				<view class="name">用药建议</view>
			</view>
			<view class="part3">
				<block v-for="(item, index) in info.doctor_prescription_access" :key="index">
					<view class="item">
						<view class="p1 flex-row-between">
							<view class="l bg-cover" :style="{backgroundImage: 'url(' + item.goods_img + ')'}"></view>
							<view class="m flex-1 flex-column-between">
								<view class="font14">{{item.goods_name}}</view>
								<view class="font12 font-969696">{{item.spec_name}}</view>
								<view class="font14 font-ff4646">￥{{item.goods_price}}</view>
							</view>
							<view class="r font14">×{{item.number}}</view>
						</view>
						<view class="p2 font12 font-969696">用法用量：{{item.frequencys}}，{{item.consumptions}}，{{item.usages}}</view>
						<view class="p2 font12 font-969696">备注：{{item.remark||'--'}}</view>
					</view>
				</block>
			</view>
			<!-- 审核药师 -->
			<block v-if="info.status != 'normal'">
				<view class="title flex-row-between">
					<view class="name">审核药师</view>
					<view v-if="info.pharmacist_time" class="font12 font-969696">审核时间：{{info.pharmacist_time}}</view>
				</view>
				<view class="part1 font12 flex-row-start">
					<image class="photo" :src="$base.cdn(info&&info.pharmacist_info?info.pharmacist_info.img:'','/static/lj/common/default-doctor.png')" mode="aspectFill"></image>
					<text>{{info&&info.pharmacist_info?info.pharmacist_info.name:''}}</text>
					<text>{{info&&info.pharmacist_info?info.pharmacist_info.mobile:''}}</text>
				</view>
			</block>
		</view>
		<!-- 按钮 -->
		<view v-if="info.status == 'reject'" class="fix-bottom-btn flex-row-center">
			<view class="btn l flex-row-center" @click="onCancel">取消</view>
			<view class="btn r flex-row-center" @click="onEdit">编辑</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				photo: require('../../static/my/portrait.png'),
				info: {},
				
				doctor_prescription_id: 0,
				chat_id: 0,
			}
		},
		onLoad: function(options) {
			if(options.id) this.doctor_prescription_id = options.id
			if(options.chat_id) this.chat_id = options.chat_id
		},
		onShow(){
			this.init()
		},
		methods: {
			init(){
				let $this = this
				this.$Http({
					url: 'detailsPrescription',
					data: {doctor_prescription_id: this.doctor_prescription_id}
				}).then(res => {
					if (res.code == 1) {
						res.data.doctor_info.img = $this.$store.state.http_img + res.data.doctor_info.img
						res.data.pharmacist_time = res.data.pharmacist_time ? $this.$base.formatTime(new Date(res.data.pharmacist_time * 1000), 'yyyy-MM-dd hh:mm:ss') : ''
						res.data.doctor_prescription_access.forEach((item)=>{
							item.goods_img = $this.$store.state.http_img + item.goods_img
						})
						$this.info = res.data
					} else {
						uni.showToast({ title: res.msg, icon: 'none' })
					}
				})
			},
			Oncontent(e){
				this.reject_content = e.detail.value
			},
			// 取消
			onCancel () {
				this.$Http({
					url: 'hiddenPrescription',
					data: {doctor_prescription_id: this.info.id}
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({ title: '操作成功' })
						setTimeout(()=>{
							uni.navigateBack({ delta: 1 });
						}, 2000)
					} else {
						uni.showToast({ title: res.msg, icon: 'none' })
					}
				})
			},
			// 编辑
			onEdit (url) {
				uni.navigateTo({
					url:  '/pagesA/prescript/doctorEditPrescript?prescriptId=' + this.doctor_prescription_id + '&chatId=' + this.chat_id
				})
			},
			// 跳转
			goNext (url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="less">
	@import url("style.less");
	
	.order-detail .status {
	    line-height: 1.5;
	    padding: 6px 12px;
	}
</style>
